//
//  PlaceListTVC.swift
//  placepic
//
//  Created by 이유진 on 2020/07/02.
//  Copyright © 2020 elesahich. All rights reserved.
//

import UIKit
import Kingfisher

class PlaceListTVC: UITableViewCell {
    static let identifier: String = "PlaceListTVC"
    
    @IBOutlet weak var placeName: UILabel!
    @IBOutlet weak var placeSubway: UILabel!
    @IBOutlet weak var placeDate: UILabel!
    @IBOutlet weak var placePhoto: UIImageView!
    @IBOutlet weak var placeWriter: UIImageView!
    @IBOutlet weak var writerName: UILabel!
    @IBOutlet weak var bottomSeperatorView: UIView!
    @IBOutlet var placeTag: [UITextField]!
    @IBOutlet var keywordWidthConstant: [NSLayoutConstraint]!
    //210
    override func awakeFromNib() {
        super.awakeFromNib()
        
        setupBottomSeperatorView()
        
        placeWriter.layer.cornerRadius = placeWriter.frame.height/2
        for i in 0..<3 {
            placeTag[i].layer.borderWidth = 0.0
        }
        placeTag[1].layer.borderWidth = 0.0
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        for (index) in placeTag.indices {
            guard index < 3 else { continue }
            let contentSize = placeTag[index].sizeThatFits(placeTag[index].bounds.size)
            keywordWidthConstant[index].constant = contentSize.width - 10
            placeTag[index].contentVerticalAlignment = .center
        }
    }
    
    private func setupBottomSeperatorView() {
        bottomSeperatorView.backgroundColor = .blueGray20
    }

    func setPlaceInfo(pName: String,
                      pSubway:String,
                      pDate:String,
                      pPhoto:String,
                      pWriter: String,
                      wName:String,
                      pTag1:String,
                      pTag2:String,
                      pTag3:String) {
        placeName.text = pName
        placeSubway.text = pSubway
        placeDate.text = pDate
        placePhoto.kf.setImage(with: URL(string: pPhoto))
        placeWriter.kf.setImage(with: URL(string: pWriter))
        placePhoto.layer.cornerRadius = 4
        writerName.text = wName
        placeTag[0].text = pTag1
        placeTag[1].text = pTag2
        placeTag[2].text = pTag3
       
        for i in 0..<3{
            placeTag[i].clipsToBounds = true
            placeTag[i].layer.borderWidth = 2
            placeTag[i].layer.borderColor = UIColor(red: 0.945, green: 0.957, blue: 0.961, alpha: 1).cgColor
            placeTag[i].backgroundColor = UIColor(red: 0.945, green: 0.957, blue: 0.961, alpha: 1)
            placeTag[i].layer.cornerRadius = 4
            placeTag[i].isEnabled = false
        }
    }
}
